version 14
set more off
set matsize 11000

***************************************************************************************************
* THIS ROUTINE GENERATES TABLE A.IX OF WASEEM (2019) RESTAT
***************************************************************************************************

/* TABLE */

#d				;
matrix 			input table=(0,0,0,0,0,0,0,0,0,0,0,0\0,0,0,0,0,0,0,0,0,0,0,0\
							 0,0,0,0,0,0,0,0,0,0,0,0\0,0,0,0,0,0,0,0,0,0,0,0\
							 0,0,0,0,0,0,0,0,0,0,0,0\0,0,0,0,0,0,0,0,0,0,0,0\
							 0,0,0,0,0,0,0,0,0,0,0,0\0,0,0,0,0,0,0,0,0,0,0,0\
							 0,0,0,0,0,0,0,0,0,0,0,0\0,0,0,0,0,0,0,0,0,0,0,0);
#d				cr
use				"$project_data\ExemptionCutoff_06_11.dta",clear
keep			if employee==1

/* BINNING DATA */

local 			var="wageinc"
local 			ubound=700000
local 			lbound=140000								
g 				double z0=`var'
sort			regnor year
g 				z1=F1.`var'
g 				logchange=log(z1/z0)
keep 			if z0>`lbound' & z0<=`ubound'
qui				sum logchange,d
drop			if (logchange<r(p1) | logchange>r(p99)) 
g				logz0=log(z0)
mkspline 		z0s 10 = logz0

/* GENERATING TREATMENT DUMMIES */

g				tozero=0
replace			tozero=1 if `var'>150000 & `var'<180000 
replace			tozero=1 if `var'>180000 & `var'<200000 
replace			tozero=1 if `var'>200000 & `var'<300000 
replace			tozero=1 if `var'>300000 & `var'<350000 
g				tozero_year=0
replace			tozero_year=1 if `var'>150000 & `var'<180000 & year==2007
replace			tozero_year=1 if `var'>180000 & `var'<200000 & year==2008
replace			tozero_year=1 if `var'>200000 & `var'<300000 & year==2009
replace			tozero_year=1 if `var'>300000 & `var'<350000 & year==2010
g				nottozero=0
replace			nottozero=1 if `var'>300000 & `var'<450000
replace			nottozero=1 if `var'>500000 & `var'<550000
replace			nottozero=1 if `var'>600000 & `var'<650000
g				nottozero_year=0
replace			nottozero_year=1 if `var'>300000 & `var'<450000 & year==2007
replace			nottozero_year=1 if `var'>500000 & `var'<550000 & year==2007
replace			nottozero_year=1 if `var'>600000 & `var'<650000 & year==2007
g				trend=1
local			i=1
forvalues		y=2007/2011 {
local			i=`i'+1
replace			trend=`i' if year==`y'
}
g				bottom=(`var'<=300000)
g				trend_bottom=trend*bottom

/* COLUMN (1) -- BASELINE */

local			i=1
local			j=1
qui				reg logchange i.year tozero nottozero tozero_year nottozero_year z0s* , cluster(regnor) 
matrix			table[`i',`j']=_b[tozero_year]
matrix			table[`i'+1,`j']=_se[tozero_year]
local			i=`i'+2
matrix			table[`i',`j']=_b[nottozero_year]
matrix			table[`i'+1,`j']=_se[nottozero_year]
local			i=`i'+6
matrix			table[`i',`j']=e(N)
local			i=`i'+1
qui				sum logchange if tozero_year==0
matrix 			table[`i',`j']=r(mean)
local			j=`j'+1

/* COLUMN (2) -- ADDITIONAL CONTROLS (Region) */

local			i=1
qui				reg logchange i.year tozero nottozero tozero_year nottozero_year i.location_code z0s*  if location_code>=0, cluster(regnor) 
matrix			table[`i',`j']=_b[tozero_year]
matrix			table[`i'+1,`j']=_se[tozero_year]
local			i=`i'+2
matrix			table[`i',`j']=_b[nottozero_year]
matrix			table[`i'+1,`j']=_se[nottozero_year]
local			i=`i'+6
matrix			table[`i',`j']=e(N)
local			i=`i'+1
qui				sum logchange if tozero_year==0
matrix 			table[`i',`j']=r(mean)
local			j=`j'+1

/* COLUMN (3) -- ADDITIONAL CONTROLS (Tax Office) */

local			i=1
qui				reg logchange i.year tozero nottozero tozero_year nottozero_year i.tax_office_id z0s* , cluster(regnor) 
matrix			table[`i',`j']=_b[tozero_year]
matrix			table[`i'+1,`j']=_se[tozero_year]
local			i=`i'+2
matrix			table[`i',`j']=_b[nottozero_year]
matrix			table[`i'+1,`j']=_se[nottozero_year]
local			i=`i'+6
matrix			table[`i',`j']=e(N)
local			i=`i'+1
qui				sum logchange if tozero_year==0
matrix 			table[`i',`j']=r(mean)
local			j=`j'+1

/* COLUMN (4) -- ADDITIONAL CONTROLS (Age Deciles) */

g 				birthdate = date(birth_foundation_date, "DMY")			
g 				birthyear=year(birthdate)
g 				age_birth=2009-birthyear
xtile 			agedec=age_birth,nq(10)								
local			i=1
qui				reg logchange i.year tozero nottozero tozero_year nottozero_year i.agedec z0s* , cluster(regnor) 
matrix			table[`i',`j']=_b[tozero_year]
matrix			table[`i'+1,`j']=_se[tozero_year]
local			i=`i'+2
matrix			table[`i',`j']=_b[nottozero_year]
matrix			table[`i'+1,`j']=_se[nottozero_year]
local			i=`i'+6
matrix			table[`i',`j']=e(N)
local			i=`i'+1
qui				sum logchange if tozero_year==0
matrix 			table[`i',`j']=r(mean)
local			j=`j'+1

/* COLUMN (5) -- ADDITIONAL CONTROLS (Years-registered Deciles) */

g 				regdate = date(registration_date, "DMY")			
g 				regyear=year(regdate)
g 				age_reg=2009-regyear
xtile 			regdec=age_reg,nq(10)								
local			i=1
qui				reg logchange i.year tozero nottozero tozero_year nottozero_year i.regdec z0s* , cluster(regnor) 
matrix			table[`i',`j']=_b[tozero_year]
matrix			table[`i'+1,`j']=_se[tozero_year]
local			i=`i'+2
matrix			table[`i',`j']=_b[nottozero_year]
matrix			table[`i'+1,`j']=_se[nottozero_year]
local			i=`i'+6
matrix			table[`i',`j']=e(N)
local			i=`i'+1
qui				sum logchange if tozero_year==0
matrix 			table[`i',`j']=r(mean)
local			j=`j'+1

/* COLUMN (6) -- ADDITIONAL CONTROLS (Region & Tax Office) */

local			i=1
qui				reg logchange i.year tozero nottozero tozero_year nottozero_year i.regdec i.location_code i.tax_office_id z0s*  if location_code>=0, cluster(regnor) 
matrix			table[`i',`j']=_b[tozero_year]
matrix			table[`i'+1,`j']=_se[tozero_year]
local			i=`i'+2
matrix			table[`i',`j']=_b[nottozero_year]
matrix			table[`i'+1,`j']=_se[nottozero_year]
local			i=`i'+6
matrix			table[`i',`j']=e(N)
local			i=`i'+1
qui				sum logchange if tozero_year==0
matrix 			table[`i',`j']=r(mean)
local			j=`j'+1

/* COLUMN (7) -- DROPPING BUNCHERS */

#d				;
matrix 			input bunch_we=     (2006,200,1,0.75,250,2,0.75,300,2,3  ,350,2,4  ,400,2,5\
									 2007,200,1,0.75,250,2,0.75,300,2,3  ,350,2,4  ,400,2,5\
									 2008,250,2,1   ,350,2,3   ,400,2,2.5,450,2,2.5,550,3,6\
									 2009,350,2,3   ,400,2,2.5 ,450,2,2.5,550,3,6,     0,0,0\
									 2010,400,2,2.5 ,450,2,2.5 ,550,3,6  ,0,0,0,       0,0,0\
									 2011,400,2,2.5 ,450,2,2.5 ,550,3,6  ,0,0,0,       0,0,0);
#d				cr
local			k=1
local			l=2
g				buncher=0
forvalues		y=2006/2011 {
forvalues 		n_notch=1(1)5 {
				local notch=bunch_we[`k',`l']*1000
				local lower=`notch' - (bunch_we[`k',`l'+1]*1000)
				local upper=`notch' + (bunch_we[`k',`l'+2]*1000)
				replace buncher=1 if taxableinc>`lower' & taxableinc<=`upper' & year==`y'
				local l=`l'+3
				}
				local k=`k'+1
				local l=2
}
drop			if buncher==1
local			i=1
qui				reg logchange i.year tozero nottozero tozero_year nottozero_year z0s* , cluster(regnor) 
matrix			table[`i',`j']=_b[tozero_year]
matrix			table[`i'+1,`j']=_se[tozero_year]
local			i=`i'+2
matrix			table[`i',`j']=_b[nottozero_year]
matrix			table[`i'+1,`j']=_se[nottozero_year]
local			i=`i'+6
matrix			table[`i',`j']=e(N)
local			i=`i'+1
qui				sum logchange if tozero_year==0
matrix 			table[`i',`j']=r(mean)
local			j=`j'+1

/* COLUMN 8 -- FULL SAMPLE */

use				"$project_data\ExemptionCutoff_06_11.dta",clear
keep			if employee==1
local 			var="wageinc"
local 			ubound=1000000
g 				double z0=`var'
sort			regnor year
g 				z1=F1.`var'
g 				logchange=log(z1/z0)
keep 			if z0<=`ubound'
qui				sum logchange,d
drop			if (logchange<r(p1) | logchange>r(p99)) 
g				tozero=0
replace			tozero=1 if `var'>150000 & `var'<180000 
replace			tozero=1 if `var'>180000 & `var'<200000 
replace			tozero=1 if `var'>200000 & `var'<300000 
replace			tozero=1 if `var'>300000 & `var'<350000 
g				tozero_year=0
replace			tozero_year=1 if `var'>150000 & `var'<180000 & year==2007
replace			tozero_year=1 if `var'>180000 & `var'<200000 & year==2008
replace			tozero_year=1 if `var'>200000 & `var'<300000 & year==2009
replace			tozero_year=1 if `var'>300000 & `var'<350000 & year==2010
g				nottozero=0
replace			nottozero=1 if `var'>300000 & `var'<450000
replace			nottozero=1 if `var'>500000 & `var'<550000
replace			nottozero=1 if `var'>600000 & `var'<650000
g				nottozero_year=0
replace			nottozero_year=1 if `var'>300000 & `var'<450000 & year==2007
replace			nottozero_year=1 if `var'>500000 & `var'<550000 & year==2007
replace			nottozero_year=1 if `var'>600000 & `var'<650000 & year==2007
g				trend=1
local			i=1
forvalues		y=2007/2011 {
local			i=`i'+1
replace			trend=`i' if year==`y'
}
g				bottom=(`var'<=300000)
g				trend_bottom=trend*bottom
g				logz0=log(z0)
mkspline 		z0s 10 = logz0
local			i=1
qui				reg logchange i.year tozero nottozero tozero_year nottozero_year z0s* , cluster(regnor) 
matrix			table[`i',`j']=_b[tozero_year]
matrix			table[`i'+1,`j']=_se[tozero_year]
local			i=`i'+2
matrix			table[`i',`j']=_b[nottozero_year]
matrix			table[`i'+1,`j']=_se[nottozero_year]
local			i=`i'+6
matrix			table[`i',`j']=e(N)
local			i=`i'+1
qui				sum logchange if tozero_year==0
matrix 			table[`i',`j']=r(mean)

/* PLACEBO */

use				"$project_data\ExemptionCutoff_06_11.dta",clear
keep			if employee==1

/* BINNING DATA */

local 			var="wageinc"
local 			ubound=700000
local 			lbound=140000								
g 				double z0=`var'
sort			regnor year
g 				z1=F1.`var'
g 				logchange=log(z1/z0)
keep 			if z0>`lbound' & z0<=`ubound'
qui				sum logchange,d
drop			if (logchange<r(p1) | logchange>r(p99)) 


/* GENERATING TREATMENT DUMMIES */

g				tozero=0
replace			tozero=1 if `var'>150000 & `var'<180000
replace			tozero=1 if `var'>180000 & `var'<200000 
replace			tozero=1 if `var'>200000 & `var'<300000 
replace			tozero=1 if `var'>300000 & `var'<350000 
g				tozero_year=0
replace			tozero_year=1 if `var'>150000 & `var'<180000 & year==2006
replace			tozero_year=1 if `var'>180000 & `var'<200000 & year==2007
replace			tozero_year=1 if `var'>200000 & `var'<300000 & year==2008
replace			tozero_year=1 if `var'>300000 & `var'<350000 & year==2009
g				nottozero=0
replace			nottozero=1 if `var'>300000 & `var'<450000
replace			nottozero=1 if `var'>500000 & `var'<550000
replace			nottozero=1 if `var'>600000 & `var'<650000
g				nottozero_year=0
replace			nottozero_year=1 if `var'>300000 & `var'<450000 & year==2006
replace			nottozero_year=1 if `var'>500000 & `var'<550000 & year==2006
replace			nottozero_year=1 if `var'>600000 & `var'<650000 & year==2006
g				trend=1
local			i=1
forvalues		y=2007/2011 {
local			i=`i'+1
replace			trend=`i' if year==`y'
}
g				bottom=(`var'<=300000)
g				trend_bottom=trend*bottom
g				logz0=log(z0)
mkspline 		z0s 10 = logz0

/* COLUMN (1) -- BASELINE */

local			i=5
local			j=1
qui				reg logchange i.year tozero nottozero tozero_year nottozero_year z0s* , cluster(regnor) 
matrix			table[`i',`j']=_b[tozero_year]
matrix			table[`i'+1,`j']=_se[tozero_year]
local			i=`i'+2
matrix			table[`i',`j']=_b[nottozero_year]
matrix			table[`i'+1,`j']=_se[nottozero_year]
local			j=`j'+1

/* COLUMN (2) -- ADDITIONAL CONTROLS (Region) */

local			i=5
qui				reg logchange i.year tozero nottozero tozero_year nottozero_year i.location_code z0s*  if location_code>=0, cluster(regnor) 
matrix			table[`i',`j']=_b[tozero_year]
matrix			table[`i'+1,`j']=_se[tozero_year]
local			i=`i'+2
matrix			table[`i',`j']=_b[nottozero_year]
matrix			table[`i'+1,`j']=_se[nottozero_year]
local			j=`j'+1

/* COLUMN (3) -- ADDITIONAL CONTROLS (Tax Office) */

local			i=5
qui				reg logchange i.year tozero nottozero tozero_year nottozero_year i.tax_office_id z0s* , cluster(regnor) 
matrix			table[`i',`j']=_b[tozero_year]
matrix			table[`i'+1,`j']=_se[tozero_year]
local			i=`i'+2
matrix			table[`i',`j']=_b[nottozero_year]
matrix			table[`i'+1,`j']=_se[nottozero_year]
local			j=`j'+1

/* COLUMN (4) -- ADDITIONAL CONTROLS (Age Deciles) */

g 				birthdate = date(birth_foundation_date, "DMY")			
g 				birthyear=year(birthdate)
g 				age_birth=2009-birthyear
xtile 			agedec=age_birth,nq(10)								
local			i=5
qui				reg logchange i.year tozero nottozero tozero_year nottozero_year i.agedec z0s* , cluster(regnor) 
matrix			table[`i',`j']=_b[tozero_year]
matrix			table[`i'+1,`j']=_se[tozero_year]
local			i=`i'+2
matrix			table[`i',`j']=_b[nottozero_year]
matrix			table[`i'+1,`j']=_se[nottozero_year]
local			j=`j'+1

/* COLUMN (5) -- ADDITIONAL CONTROLS (Years-registered Deciles) */

g 				regdate = date(registration_date, "DMY")			
g 				regyear=year(regdate)
g 				age_reg=2009-regyear
xtile 			regdec=age_reg,nq(10)								
local			i=5
qui				reg logchange i.year tozero nottozero tozero_year nottozero_year i.regdec z0s* , cluster(regnor) 
matrix			table[`i',`j']=_b[tozero_year]
matrix			table[`i'+1,`j']=_se[tozero_year]
local			i=`i'+2
matrix			table[`i',`j']=_b[nottozero_year]
matrix			table[`i'+1,`j']=_se[nottozero_year]
local			j=`j'+1

/* COLUMN (6) -- ADDITIONAL CONTROLS (Region & Tax Office) */

local			i=5
qui				reg logchange i.year tozero nottozero tozero_year nottozero_year i.regdec i.location_code i.tax_office_id z0s*  if location_code>=0, cluster(regnor) 
matrix			table[`i',`j']=_b[tozero_year]
matrix			table[`i'+1,`j']=_se[tozero_year]
local			i=`i'+2
matrix			table[`i',`j']=_b[nottozero_year]
matrix			table[`i'+1,`j']=_se[nottozero_year]
local			j=`j'+1

/* COLUMN (7) -- DROPPING BUNCHERS */

#d				;
matrix 			input bunch_we=     (2006,200,1,0.75,250,2,0.75,300,2,3  ,350,2,4  ,400,2,5\
									 2007,200,1,0.75,250,2,0.75,300,2,3  ,350,2,4  ,400,2,5\
									 2008,250,2,1   ,350,2,3   ,400,2,2.5,450,2,2.5,550,3,6\
									 2009,350,2,3   ,400,2,2.5 ,450,2,2.5,550,3,6,     0,0,0\
									 2010,400,2,2.5 ,450,2,2.5 ,550,3,6  ,0,0,0,       0,0,0\
									 2011,400,2,2.5 ,450,2,2.5 ,550,3,6  ,0,0,0,       0,0,0);
#d				cr
local			k=1
local			l=2
g				buncher=0
forvalues		y=2006/2011 {
forvalues 		n_notch=1(1)5 {
				local notch=bunch_we[`k',`l']*1000
				local lower=`notch' - (bunch_we[`k',`l'+1]*1000)
				local upper=`notch' + (bunch_we[`k',`l'+2]*1000)
				replace buncher=1 if taxableinc>`lower' & taxableinc<=`upper' & year==`y'
				local l=`l'+3
				}
				local k=`k'+1
				local l=2
}
drop			if buncher==1
local			i=5
qui				reg logchange i.year tozero nottozero tozero_year nottozero_year z0s* , cluster(regnor) 
matrix			table[`i',`j']=_b[tozero_year]
matrix			table[`i'+1,`j']=_se[tozero_year]
local			i=`i'+2
matrix			table[`i',`j']=_b[nottozero_year]
matrix			table[`i'+1,`j']=_se[nottozero_year]
local			j=`j'+1

/* COLUMN 8 -- FULL SAMPLE */

use				"$project_data\ExemptionCutoff_06_11.dta",clear
keep			if employee==1
local 			var="wageinc"
local 			ubound=1000000
g 				double z0=`var'
sort			regnor year
g 				z1=F1.`var'
g 				logchange=log(z1/z0)
keep 			if z0<=`ubound'
qui				sum logchange,d
drop			if (logchange<r(p1) | logchange>r(p99)) 
g				tozero=0
replace			tozero=1 if `var'>150000 & `var'<180000
replace			tozero=1 if `var'>180000 & `var'<200000 
replace			tozero=1 if `var'>200000 & `var'<300000 
replace			tozero=1 if `var'>300000 & `var'<350000 
g				tozero_year=0
replace			tozero_year=1 if `var'>150000 & `var'<180000 & year==2006
replace			tozero_year=1 if `var'>180000 & `var'<200000 & year==2007
replace			tozero_year=1 if `var'>200000 & `var'<300000 & year==2008
replace			tozero_year=1 if `var'>300000 & `var'<350000 & year==2009
g				nottozero=0
replace			nottozero=1 if `var'>300000 & `var'<450000
replace			nottozero=1 if `var'>500000 & `var'<550000
replace			nottozero=1 if `var'>600000 & `var'<650000
g				nottozero_year=0
replace			nottozero_year=1 if `var'>300000 & `var'<450000 & year==2006
replace			nottozero_year=1 if `var'>500000 & `var'<550000 & year==2006
replace			nottozero_year=1 if `var'>600000 & `var'<650000 & year==2006
g				trend=1
local			i=1
forvalues		y=2007/2011 {
local			i=`i'+1
replace			trend=`i' if year==`y'
}
g				bottom=(`var'<=300000)
g				trend_bottom=trend*bottom
g				logz0=log(z0)
mkspline 		z0s 10 = logz0
local			i=5
qui				reg logchange i.year tozero nottozero tozero_year nottozero_year z0s* , cluster(regnor) 
matrix			table[`i',`j']=_b[tozero_year]
matrix			table[`i'+1,`j']=_se[tozero_year]
local			i=`i'+2
matrix			table[`i',`j']=_b[nottozero_year]
matrix			table[`i'+1,`j']=_se[nottozero_year]

/* FORMATTING TABLE */

svmat 			table
keep			tab*
drop			table9-table12
keep			if _n<=10
forvalues		c=1/8 {
				g c`c'=string(table`c',"%9.3f")
}
forvalues		r=2(2)8 {
forvalues		c=1/8 {
replace			c`c'="("+string(table`c',"%9.3f")+")" in `r'
}
}
forvalues		c=1/8 {
replace			c`c'=string(table`c',"%9.0fc") in 9
}
g				ci="" 
replace			ci="$\mbox{\emph{to-zero}}$" in 1
replace			ci="$\mbox{\emph{not-to-zero}}$" in 3
replace			ci="$\mbox{\emph{to-zero}}$" in 5
replace			ci="$\mbox{\emph{not-to-zero}}$" in 7
replace			ci="Observations" in 9
forvalues		s=1/12 {
g				s`s'="&"
}
g				l="\\"
browse			ci s12 c1 s1 c2 s2 c3 s3 c4 s4 c5 s5 c6 s6 c7 s7 c8 l
